<?php
class Welcome extends MY_Controller {
	var $beforeFilter = array(
			'_init' => array(
				'only' => array('index'),
			),
		);

	function __construct()
	{
		parent::MY_Controller();
	}
	
	function print_d(){
		set_time_limit(0) ;
//			$sql= ' SELECT time, count( time ) AS c
//FROM `eu_logs`
//GROUP BY time
//ORDER BY c DESC limit 6';
//		$result = $this->db->query($sql)->result_array();
//		foreach($result as $value){
//			echo date('Y-m-d H:i:s',$value['time']).'=>'.$value['c'].'<br>';
//		}
		for ( $index = strtotime('2012-12-21'); $index < strtotime('2012-12-22');$index = $index + 3600) {
			$this->data['where'] = array(
					'time >= '=>$index,
					'time <= '=>$index+ 3600,
			);
//			$sql= ' SELECT count( time ) as c 
//					FROM `eu_logs`
//					GROUP BY time
//					having time >='.$index.' and time <= '.($index + 3600).'
//					order by c desc ';
			$sql= ' SELECT count( time ) as c 
					FROM `eu_logs`
					where time >='.$index.' and time <= '.($index + 3600);
			$result = $this->db->query($sql)->row_array(); 
			$count[] = $result;
		}
		
		print_r($count);exit;
	}
	
	function index()
	{	
		set_time_limit(0) ;
		
		$file_name=FCPATH."data-log-2012-12-21.php";
		$fp=fopen($file_name,'r');
		while(!feof($fp)){
			$buffer=fgets($fp);
			$array = explode('-->',trim($buffer));
			$str = str_replace('data:  ','',$array[0]);
			
			$time = strtotime($str);
			$sql = "insert into  eu_logs " .
					"(time) " .
					"values('".$time."')";
			$result = $this->db->query($sql); 
		}
		fclose($fp);
	}
	
	function contact(){
		$this->load->model('Article');
		$rs = $this->Article->findByField(array('id'=>3));
		$this->assign['contact'] = $rs;
		$this->template = "contact";
		$this->display();
	}
	
	function about(){
		$this->load->model('Article');
		$rs = $this->Article->findByField(array('id'=>1));
		$this->assign['about'] = $rs;
		$this->template = "about";
		$this->display();
	}
	
	function job(){
		$this->template = "job";
		$this->display();
	}
	
	function article(){
		$this->load->model('Article');
		$rs = $this->Article->findByField(array('id'=>1));
		$this->assign['rs'] = $rs;
		$this->template = "article";
		$this->display();
	}
	
	
	function showarticle(){
		$this->load->model('Article');
		$this->assign['article'] = $this->Article->findByField(array('id'=>$_GET['id']));
		$this->template = "showarticle";
		$this->display();
	}
	
	function messages(){
		$this->load->model('Articlecat');
		$this->load->model('Upload');
		$this->assign['filesList'] = $this->Upload->findByField(array('is_locked'=>0,'is_flash'=>0));
		$this->assign['goodcat'] = $this->Articlecat->findByField(array('parent_id'=>2));
		$this->template = "messages";
		$this->display();
	}
	
	function brand(){
		$this->load->model('Articlecat');
		$this->assign['goodcat'] = $this->Articlecat->findByField(array('parent_id'=>2));
		$this->template = "brand";
		$this->display();
	}
	
	function flushs(){
		$this->load->model('Ftable');
		$this->Ftable->flushTable();
	}

	function test(){
		$this->load->model('SysCategory');
		$rs = $this->SysCategory->doList();
		print_r($rs);
	}
	function service(){
		$this->load->model('Article');
		$rs = $this->Article->findByField(array('id'=>100));
		$this->assign['service'] = $rs;
		$this->template = "service";
		$this->display();
	}
	
	function delivery(){
		$this->load->model('Article');
		$rs = $this->Article->findByField(array('id'=>101));
		$this->assign['delivery'] = $rs;
		$this->template = "delivery";
		$this->display();
	}
	
	function protection(){
		$this->load->model('Article');
		$rs = $this->Article->findByField(array('id'=>102));
		$this->assign['protection'] = $rs;
		$this->template = "protection";
		$this->display();
	}
	
	function copyright(){
		$this->load->model('Article');
		$rs = $this->Article->findByField(array('id'=>103));
		$this->assign['copyright'] = $rs;
		$this->template = "copyright";
		$this->display();
	}
	
	function download(){
		$this->load->model('Upload');
		$this->load->model('Articlecat');
		$this->load->model('Article');
		$this->assign['notes'] = $this->Article->findByField(array('cat_id'=>14));
		$this->assign['goodcat'] = $this->Articlecat->findByField(array('parent_id'=>2));
		$this->assign['filesList'] = $this->Upload->findByField(array('is_locked'=>0,'is_flash'=>0));
		$this->template = "download";
		$this->display();
	}
	
	function takeproduct(){
		$this->template = "takeproduct";
		$this->display();
	}
	
	function downloads(){
		$id = $_GET['id'];
		$this->load->model('Upload');
		$rs = $this->Upload->findByField(array('id'=>$id));
		$file_dir = "./data/uploads/files/"; 
		$filename = basename($rs[0]['url']);
		$this->load->helper('download');
		$data = file_get_contents($file_dir.$filename); // ���ļ�����
		if($data == '') echo '<script> alert("���ļ��Ѳ�����")</script>';
		force_download($filename, $data); 
	}
	
	function team(){
		$this->template = "team";
		$this->display();
	}
	
}